//
//  TestObjWhere.swift
//  TestSwift
//
//  Created by 小星星吃KFC on 2021/6/1.
//

import Foundation

class Student {
    var name = String()
    var age = String()
}

//public struct AXAnyMoreBase<Base,T> {
//    public let base: Base
//    public init(_ base: Base) {
//        self.base = base
//    }
//}

public struct AXAnyMoreBase<Base,T> {
    public let base: Base
    public init(_ base: Base) {
        self.base = base
    }
}
// protocol中 需要用 associatedtype 来预设一个类型
public protocol AXAnyMoreBaseProtocol {
    associatedtype type
    var ax: type { get }
}

extension AXAnyMoreBaseProtocol {
    public var ax: AXAnyMoreBase<Self,Any> {
        get {
            return AXAnyMoreBase(self)
        }
    }
}


extension AXAnyMoreBase where Base == String {
    func setString() {
        // 实现 下载图片并缓存、展示的逻辑
        
        print("AXAnyMoreBase长度=\(self.base.count)")
    }
}


/// where Base: 只能是class类型的

extension AXAnyMoreBase where Base: Student, T:Student {
    func setStudent() {
        // 实现 下载图片并缓存、展示的逻辑
        
        self.base.name = "tom"
        
        print("Student=\(self.base.name),\(self.base.age)")
        
        
    }
}

extension AXAnyMoreBase where Base: Student, T:Any {
    func setStudent() {
        // 实现 下载图片并缓存、展示的逻辑
        
        self.base.name = "tom"
        
        print("Student=\(self.base.name),\(self.base.age)")
        
        
    }
}

func TestObjWhere() {
    var name: String
    name = "jim"
    
    let kit  = AXAnyMoreBase<String, Any>("jim")
    kit.setString()
    do {
        var st = Student()
        st.name = "jim"
        st.age = "10"
        let kit  = AXAnyMoreBase<Student, Any>(st)
        kit.setStudent()
        print("Student st=\(st.name),\(st.age)")
        
        
    }
    
    
}




